//
//  ListTableViewCell.swift
//  旅航ios
//
//  Created by tulip on 2021/4/25.
//

import UIKit
import SwiftyJSON

class ListTableViewCell: UITableViewCell,UICollectionViewDelegate,UICollectionViewDataSource,WaterflowLayoutDelegate {
  
    var data:[JSON]=[]
    
    @IBOutlet weak var collect: UICollectionView!
    override func awakeFromNib() {
        super.awakeFromNib()
    
        let layout = HCFallsFlowLayout.init()
        
        //... 设置UIEdgeinset 行间距 列间距 可以自己定义
        layout.interitemSpacing=15
       // layout.edgeInset=
        layout.lineSpacing=15
        layout.basicSetting()
        //设置几列 默认是2列
        layout.columCount = 2
        layout.mydelegate = self
        
        layout.headerReferenceSize=CGSize(width: SCREEN_WIDTH, height: 35)
    
    collect.backgroundColor=UIColor.clear
    collect.collectionViewLayout=layout
    collect.delegate=self
    collect.dataSource=self
    collect.isPagingEnabled=true
  //  collect.contentOffset=CGPoint(x: SCREEN_WIDTH, y: 0)
    collect.showsHorizontalScrollIndicator=false
    collect.register(UINib(nibName: "ListCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "ListCollectionViewCell")
   
 
  collect.register(CollectionHeaderView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "CollectionHeaderView")
      
        
        Network.request(.home) { (JSON) in
            self.data=JSON["data"]["recommend"]["aircraft"].array ?? []
            self.collect.reloadData()
        } failure: { (err) in
            
        }

        
   
    
}

override func setSelected(_ selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)
    
    self.selectionStyle = .none
}

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    data.count
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
     
}
    
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell:ListCollectionViewCell=collectionView.dequeueReusableCell(withReuseIdentifier: "ListCollectionViewCell", for: indexPath) as! ListCollectionViewCell

    let url=data[indexPath.row]["img"].string ?? ""
    cell.img.kf.setImage(with: URL(string: url))
    cell.imgHeight.constant=cell.frame.size.height-105
    cell.bottomTagBox=gradientColor(colo1: "15c67f", colo2: "5ddea7", view: cell.bottomTagBox,width: cell.bottomTagBox.frame.size.width)
    cell.bottomTagBox.layer.cornerRadius=3
    
    cell.toptagBox=gradientColor(colo1: "15c67f", colo2: "5ddea7", view: cell.toptagBox,width: cell.toptagBox.frame.size.width)
    cell.toptagBox.layer.cornerRadius=8
    return cell
}


    func collectionView(_ collectionView: UICollectionView, heightForItemAt indexPath: IndexPath) -> CGFloat {
        return CGFloat.random(in: 250...300)
    }
    
    
    func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
        let header:CollectionHeaderView=collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "CollectionHeaderView", for: indexPath) as! CollectionHeaderView
         
        
        header.backgroundColor=UIColor.red
        return header
    }
    
    

    
    

}
